package com.qmo.edu.moudle.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import android.widget.TextView;

import com.qmo.edu.R;
import com.qmo.edu.moudle.bean.GetAlarmBean;


import java.util.List;



/**
 * Created by ${} on 2019/6/2/002.
 *
 * @author cyx
 */
public class AlarmAdapter extends RecyclerView.Adapter<AlarmAdapter.MyViewHolder> {
    private Context mContext;
    private List<GetAlarmBean.ItemsBean> mList;

    public AlarmAdapter(Context context, List<GetAlarmBean.ItemsBean> list) {
        mContext = context;
        mList = list;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_alarm, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int i) {
        String desc = mList.get(i).getAlarmType();
        if (desc.equals("1")) {
            myViewHolder.mOne.setTextColor(mContext.getResources().getColor(R.color.alarm_ybcx));
        } else if (desc.equals("2")) {
            myViewHolder.mOne.setTextColor(mContext.getResources().getColor(R.color.alarm_dsyc));
        } else if (desc.equals("3")) {
            myViewHolder.mOne.setTextColor(mContext.getResources().getColor(R.color.alarm_sbgz));
        } else if (desc.equals("4")) {
            myViewHolder.mOne.setTextColor(mContext.getResources().getColor(R.color.alarm_txzd));
        }

        myViewHolder.mOne.setText(mList.get(i).getAlarmDesc());
        myViewHolder.mTwo.setText(mList.get(i).getDtDate());
        myViewHolder.mThree.setText(mList.get(i).getAlarmContent());

    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        private final TextView mOne;
        private final TextView mTwo;
        private final TextView mThree;


        public MyViewHolder(@NonNull View itemView) {
            super(itemView);

            mOne = itemView.findViewById(R.id.tv_alarm_name);
            mTwo = itemView.findViewById(R.id.tv_alarm_time);
            mThree = itemView.findViewById(R.id.tv_des);

        }
    }

    private OnItemClickListener mOnItemClickListener = null;

    public interface OnItemClickListener {
        void onItemClick(View view, int position);

        void onCheckBoxClick(Boolean isCheck, int position);
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }
}
